// const { think } = require('thinkjs');
// const moment = require('moment');
const { think } = require('thinkjs');
const Base = require('./base.js');
const cid = require('@4a/cid');
const { default: BigNumber } = require('bignumber.js');

module.exports = class extends Base {
  async getOrderAction() {
    const orders = await this.model('order_list').where({order_no: this.get('no'), user_id: this.getLoginUserId()}).alias('a').join({
      product_list: {
        join: 'left',
        as: 'd',
        on: ['product_id', 'id']
      }
    }).field('d.name, d.price, a.*').select();
    let money = 0;
    for (const item of orders) {
      money = BigNumber(money).plus(BigNumber(item.price));
    }
    // const money = BigNumber().plus(BigNumber());

    return this.success({
      order_no: this.get('no'),
      money: money
    });
  }

  async getPayAction() {
    const orders = await this.model('order_list').where({order_no: this.get('no'), user_id: this.getLoginUserId()}).select();
    return this.success(orders);
  }
  async commentAction() {
    const data = await this.model('order_comment').alias('a').join({
      user_list: {
        join: 'left',
        as: 'u',
        on: ['user_id', 'id']
      }
    }).field('u.name, u.phone, a.*').order(['id DESC']).where({product_id: this.get('id')}).select();
    return this.success(data);
  }
};
